<?php
class NewsAction extends AgriculturalproductsCommonAction {

	
	public function index() {
		
		//取最新的一个分类头条新闻
		
		$queryString_topCatalog = "select * from news where publishcatalog =1 and status =1 order by statusdate desc  LIMIT 1";			
		$this->assign("topCatalogsList",$this->CommonSimplequery(1,$queryString_topCatalog ,'' ,'' ,0,""));
		
		//顶部列表
		$queryString_top = "select * from news where status =1 order by statusdate desc  LIMIT 4";			
		$this->assign("topNewsList",$this->CommonSimplequery(1,$queryString_top ,'' ,'' ,0,""));
		
		//发布图片新闻
		$queryString_image = "select * from news where status =1 and publishnewsindex =1 order by statusdate desc  LIMIT 5";			
		$this->assign("imageNewsList",$this->CommonSimplequery(1,$queryString_image ,'' ,'' ,0,""));
		
		
		
		//新闻分类展示		
		$queryString_catalog = "select b.id as catalog_id , b.`name` , b.imageurl_small from news a , news_catalog b 
								where a.news_catalog_id = b.id
								and b.`status` = 1
								group by b.name order by b.createdate desc "; 
		$catalogList = $this->CommonSimplequery(1,$queryString_catalog ,'' ,'' ,0,"") ;
		
		foreach($catalogList as $n=> $val_one){		
	      	$catalogList[$n]['one']= $this->CommonSimplequery(1,"
								      	select * from news where news_catalog_id = " . $val_one['catalog_id'] . " 
										and status = 1 
										and publishcatalog = 1 ORDER BY statusdate desc limit 1
								      	" ,'' ,'' ,0,"") ;
	      	foreach($catalogList[$n]['one'] as $j=> $val_two){   
	      		$catalogList[$n]['one'][$j]['two']= $this->CommonSimplequery(1,"
							      		select * from news where news_catalog_id = " . $val_one['catalog_id'] . " 
										and status = 1 
										ORDER BY statusdate desc limit 4;
							      		 ",'' ,'' ,0,"") ;
	      	}
	     }     
	     
		$this->assign('typeList',$catalogList);
		
		$this->rightNewsCommonQuery();
		
		$this->display();
	}
	
	

	
	/**
	 * 
	 * 新闻明细
	 */
	public function detail(){		
		$id = $_REQUEST ['id'] ;	

		//更新新闻浏览次数
		$Dao = M("news");
		$condition['id'] = $id ;
		$tempNewsVo =  $this->simpleQuery($condition,'news',1);
		$data['clicktimes'] = $tempNewsVo['clicktimes'] + 1 ;
		$Dao->where($condition)->save($data);
		
		
		//dump($this->CommonSimplequery(1,"select * from news where id = " . $id ,'' ,'' ,0,""));
		$this->assign('newsVoList',$this->CommonSimplequery(1,"select * from news where id = " . $id ,'' ,'' ,0,"")) ;

		//最近更新
		$queryString_lastUpdate = "select * from news where status =1 order by statusdate desc"; 
		$lastUpdateList = $this->CommonSimplequery(1,$queryString_lastUpdate ,'' ,'' ,0,"") ;
		$this->assign('lastUpdateList',$lastUpdateList);
		
		//推荐阅读
		$queryString_recommend = "select * from news where status =1 and publishrecommend = 1 order by statusdate desc"; 
		$recommendList = $this->CommonSimplequery(1,$queryString_recommend ,'' ,'' ,0,"") ;
		$this->assign('recommendList',$recommendList);
		
		$this->display();
	}
	
	/**
	 * 
	 * 搜索新闻
	 */
	public function search(){
		
		//$queryString_searchList = "select * from news where  status =1  and title like '%" . $_REQUEST ['id'] .  "%' order by statusdate desc  LIMIT 1";			
		//$this->assign("searchNewsList",$this->CommonSimplequery(1,$queryString_searchList ,'' ,'' ,0,""));
		
		$this->rightNewsCommonQuery();
		
		$singleCondition['status'] = 1 ;
		
		//dump(iconv("gb2312","UTF-8",$_REQUEST ['id']));
		
		$singleCondition['title'] = iconv("gb2312","UTF-8",$_REQUEST ['id']) ;
		$orderField = 'statusdate DESC' ;
		$this->getQueryPage('news',$singleCondition,$orderField);
		
		$this->display('./Tpl/default/News/list.html');
	}
	
	


}
?>